<HTML><HEAD><TITLE>phrase(+Grammar, ?List)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Control</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>phrase(+Grammar, ?List)</H1>
Succeeds if List unifies with a list from the specified grammar Grammar.


<DL>
<DT><EM>Grammar</EM></DT>
<DD>Compound term or Atom.
</DD>
<DT><EM>List</EM></DT>
<DD>List of grammar terminals (prolog terms).
</DD>
</DL>
<H2>Description</H2>
   phrase/2 can be use as a recognizer or as a generator of grammars.  As a
   recognizer, it succeeds or fails if term belongs or not to the specified
   grammar Grammar.  As a generator, it generates on backtracking all the
   elements of the grammar.

<P>
   A grammar is specified by setting the flag macro_expansion to on and by
   compiling clauses using the DCG operator --&gt;.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>phrase(+, ++) is semidet
<LI>phrase(+, -) is nondet
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Fail Conditions</H3>
List does not belong to Grammar
<H3>Resatisfiable</H3>
Depends on the particular grammar
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Grammar is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Grammar is a number or a string (i.e.  not a valid DCG    head).
</DL>
<H2>Examples</H2>
<PRE>
   [eclipse]: sh('cat gram.pl').
   sentence --&gt; noun_phrase, verb_phrase.
   noun_phrase --&gt; article, noun.
   verb_phrase --&gt; verb | verb, noun_phrase.
   article --&gt; [the].
   noun --&gt; [compiler].
   noun --&gt; [program].
   verb --&gt; [compiles].
   yes.
   [eclipse]: [gram].
   /home/user/gram.pl        compiled 732 bytes in 0.37 seconds
   yes.
   [eclipse]: phrase(sentence,[the,compiler,compiles]).
   yes.
   [eclipse]: phrase(sentence,[the,compiler,compiles,the,program]).
   yes.
   [eclipse]: phrase(sentence, X).

   X = [the, compiler, compiles]     More? (;)

   X = [the, compiler, compiles, the, compiler]     More? (;)

   X = [the, compiler, compiles, the, program]     More? (;)

   X = [the, program, compiles]     More? (;)

   X = [the, program, compiles, the, compiler]     More? (;)

   X = [the, program, compiles, the, program]
   yes.
   [eclipse]:

Fail:
   phrase(sentence, [not, a, sentence]).

Error:
   phrase(X, [what, time, is, it]).    (Error 4).
   phrase("sentence", X).              (Error 5).
   phrase(123, X).                     (Error 5).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/control/phrase-3.html">phrase / 3</A>, <A HREF="../../kernel/syntax/current_macro-4.html">current_macro / 4</A>, <A HREF="../../kernel/syntax/macro-3.html">macro / 3</A>, <A HREF="../../kernel/syntax/erase_macro-2.html">erase_macro / 2</A>
</BODY></HTML>
